package cn.ecut.servlet;

import cn.ecut.model.User;
import cn.ecut.util.StatusCode;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@WebServlet("user/Info")
public class GetUserinfoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object user=req.getSession().getAttribute("user");
        Map<String ,Object> map=new HashMap<>();
        String msg="";

        if(user instanceof User){
            msg="获取成功。";
            map.put("data",(User)user);
            map.put("msg",msg);
            map.put("status", StatusCode.SUCCESS);
        }else{
            msg="获取失败。";
            map.put("msg",msg);
            map.put("data",null);
            map.put("status",StatusCode.SERVER_ERROR);
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
